/*
 * Works.java
 *
 * Created on 12 wrzesie� 2007, 21:43
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package info.mikrotubula.db;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * Entity class Works
 * 
 * @author Krystian
 */
@Entity
@Table(name = "WORKS")
@NamedQueries( {
        @NamedQuery(name = "Works.findByWrkId", query = "SELECT w FROM Works w WHERE w.wrkId = :wrkId"),
        @NamedQuery(name = "Works.findByWrkName", query = "SELECT w FROM Works w WHERE w.wrkName = :wrkName"),
        @NamedQuery(name = "Works.findByWrkDescription", query = "SELECT w FROM Works w WHERE w.wrkDescription = :wrkDescription"),
        @NamedQuery(name = "Works.findByWrkDate", query = "SELECT w FROM Works w WHERE w.wrkDate = :wrkDate")
    })
public class Works implements Serializable {

    public Works() {
    }

    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column(name = "WRK_ID", nullable = false)
    private Integer wrkId;

    @Column(name = "WRK_NAME")
    private String wrkName;

    @Column(name = "WRK_DESCRIPTION")
    private String wrkDescription;

    @Column(name = "WRK_DATE")
    @Temporal(TemporalType.TIMESTAMP)
    private Date wrkDate;

    @JoinColumn(name = "WRK_USR_ID", referencedColumnName = "USR_ID")
    @ManyToOne
    private Users user;
    
    @OneToMany(mappedBy = "work", fetch=FetchType.LAZY)
    private Collection<Images> images;
    
    /** Creates a new instance of Works */
    public Works(String WorkName, String WorkDescription, Date WorkDate, Users WorkUser) {
        this.wrkName = WorkName;
        this.wrkDescription = WorkDescription;
        this.wrkDate = WorkDate;
        this.setUser(WorkUser);
    }

    /**
     * Creates a new instance of Works with the specified values.
     * @param wrkId the wrkId of the Works
     */
    public Works(Integer wrkId) {
        this.wrkId = wrkId;
    }

    /**
     * Gets the wrkId of this Works.
     * @return the wrkId
     */
    public Integer getWrkId() {
        return this.wrkId;
    }

    /**
     * Sets the wrkId of this Works to the specified value.
     * @param wrkId the new wrkId
     */
    public void setWrkId(Integer wrkId) {
        this.wrkId = wrkId;
    }

    /**
     * Gets the wrkName of this Works.
     * @return the wrkName
     */
    public String getWrkName() {
        return this.wrkName;
    }

    /**
     * Sets the wrkName of this Works to the specified value.
     * @param wrkName the new wrkName
     */
    public void setWrkName(String wrkName) {
        this.wrkName = wrkName;
    }

    /**
     * Gets the wrkDescription of this Works.
     * @return the wrkDescription
     */
    public String getWrkDescription() {
        return this.wrkDescription;
    }

    /**
     * Sets the wrkDescription of this Works to the specified value.
     * @param wrkDescription the new wrkDescription
     */
    public void setWrkDescription(String wrkDescription) {
        this.wrkDescription = wrkDescription;
    }

    /**
     * Gets the wrkDate of this Works.
     * @return the wrkDate
     */
    public Date getWrkDate() {
        return this.wrkDate;
    }

    /**
     * Sets the wrkDate of this Works to the specified value.
     * @param wrkDate the new wrkDate
     */
    public void setWrkDate(Date wrkDate) {
        this.wrkDate = wrkDate;
    }

    /**
     * Returns a hash code value for the object.  This implementation computes 
     * a hash code value based on the id fields in this object.
     * @return a hash code value for this object.
     */
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (this.wrkId != null ? this.wrkId.hashCode() : 0);
        return hash;
    }

    /**
     * Determines whether another object is equal to this Works.  The result is 
     * <code>true</code> if and only if the argument is not null and is a Works object that 
     * has the same id field values as this object.
     * @param object the reference object with which to compare
     * @return <code>true</code> if this object is the same as the argument;
     * <code>false</code> otherwise.
     */
    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Works)) {
            return false;
        }
        Works other = (Works)object;
        if (this.wrkId != other.wrkId && (this.wrkId == null || !this.wrkId.equals(other.wrkId))) return false;
        return true;
    }

    /**
     * Returns a string representation of the object.  This implementation constructs 
     * that representation based on the id fields.
     * @return a string representation of the object.
     */
    @Override
    public String toString() {
        return "info.mikrotubula.db.Works[wrkId=" + wrkId + "]";
    }

    public Users getUser() {
        return user;
    }

    public void setUser(Users user) {
        this.user = user;
    }

    public Collection<Images> getImages() {
        return images;
    }

    public void setImages(Collection<Images> images) {
        this.images = images;
    }
    
}
